const { exec } = require('../db/index')
// 增加 删除 修改 查询
const getList = async () => {
  const sql = `select * from users;`
  return await exec(sql)
}

const addItem = async({username,password,realname}) => {
  console.log(username, password, realname, '-----real')
  let sql = `
  insert into users (username, password, realname)
  values ('${username}', '${password}', ${realname});`
  return await exec(sql)
}

const updateItem = async(id, username, password, realname) => {
  let sql = `update users set username='${username}' password='${password}' realname='${realname}' where id = ${id};`  
  return await exec(sql)  
}

const deleteItem = async (id) => {
  const sql = `delete from users where id = ${id};`
  return await exec(sql)
}

module.exports = {
  getList,
  updateItem,
  addItem,
  deleteItem
}